﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace SilverlightControls.Designer
{
    public class FormDesigner: ContentControl
    {
        public FormDesigner()
        {
            DefaultStyleKey = typeof(FormDesigner);
            Resources.Source = new Uri("/SilverlightControls;component/Designer/Themes/Generic.xaml", UriKind.Relative);
        }

        private TabControl _tabControl;
        private PropertyGrid _propertyGrid;
        private Toolbox _toolBox;
        private FormContent _content;

        public FormContent FormContent { get { return _content; } }

        #region Overrides

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _tabControl = (TabControl)GetTemplateChild("_tabControl");
            _propertyGrid = (PropertyGrid)GetTemplateChild("_propertyGrid");
            _toolBox = (Toolbox)GetTemplateChild("_toolBox");
            _content = (FormContent)GetTemplateChild("_content");
            _propertyGrid.SelectedObject = _content;
            _toolBox.Designer = this;
            _content.PropertyGrid = _propertyGrid;
        }

        #endregion
    }
}
